import LoadingComponent from './loading.vue'

const Loading = {};

// install

Loading.install = function (Vue) {
  const LoadingConstructor = Vue.extend(LoadingComponent)
    
  const instance = new LoadingConstructor();
  // 将这个实例挂载在我创建的div上
  // 并将此div加入全局挂载点内部
  instance.$mount(document.createElement('div'))
  document.body.appendChild(instance.$el)

  // 通过Vue的原型注册一个方法
  // 让所有实例共享这个方法 
  Vue.prototype.$loading = (show = false, type = 'auto',duration = 1500) => {
    if (type == "hand") instance.visible = show
    else {
      instance.visible = true;
      setTimeout(() => {
        instance.visible = false;
      }, duration)
    }
  }
}

export default Loading;
